package cn.train.controler;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.train.model.Contable;
import cn.train.model.UserTable;
import cn.train.service.ContableService;
@WebServlet("/AddContServlet")
public class AddContServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		UserTable user=(UserTable)req.getSession().getAttribute("usertable");
//		System.out.println(luid);
		int uid = user.getUid();
		String cname=req.getParameter("name");
		String cidcard=req.getParameter("idcard");
		ContableService contableService=new ContableService();
		Contable contable=new Contable();
//		UserTable user=new UserTable();
//		user.setUid(uid);
//		contable.setUser(user);
		contable.setUid(uid);
		contable.setCname(cname);
		contable.setCidcard(cidcard);
		boolean flag=contableService.addCont(contable);
		if(flag) {
			req.getRequestDispatcher("GetContServlet").forward(req, resp);
		}
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req,resp);
	}
}
